package model.factories.misc;

import java.util.Map;
import java.util.Scanner;
import java.util.regex.Pattern;
import model.Interpreter;
import model.commands.Command;
import model.commands.misc.LiteralCommand;
import model.factories.CommandFactory;


/**
 * A factory that creates LiteralCommand objects.
 * 
 * @author Erick Gonzalez
 */
public class LiteralCommandFactory extends CommandFactory {
    /**
     * Pattern that matches literals.
     */
    private final Pattern myLiteralPattern = Pattern.compile("[-]?[0-9]+");

    /**
     * 
     * @param interpreter an Interpreter
     */
    public LiteralCommandFactory(Interpreter interpreter) {
        super(interpreter);
    }

    @Override
    public Command createCommand(Scanner commandReader,
                                 Map<String, Integer> variables) {
        String n = commandReader.next();        
        return new LiteralCommand(Integer.parseInt(n));
    }

    @Override
    public Pattern patternToMatch() {       
        return myLiteralPattern;
    }
}
